package com.niiwoo.civet.user.service.duboo.myCustomer;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.niiwoo.civet.trade.dto.common.InvestEvaluationDTO;
import com.niiwoo.civet.trade.service.invest.InvestDubboService;
import com.niiwoo.civet.user.dao.entity.*;
import com.niiwoo.civet.user.dto.UserPersonalDubboInfoDTO;
import com.niiwoo.civet.user.dto.request.*;
import com.niiwoo.civet.user.dto.request.myCustomer.*;
import com.niiwoo.civet.user.dto.response.*;
import com.niiwoo.civet.user.dto.response.myCustomer.*;
import com.niiwoo.civet.user.enums.*;
import com.niiwoo.civet.user.service.ActivityDubboService;
import com.niiwoo.civet.user.service.ImDubboService;
import com.niiwoo.civet.user.service.UserBasicInfoDubboService;
import com.niiwoo.civet.user.service.local.*;
import com.niiwoo.civet.user.service.local.myCustomer.MyCustomerInfoService;
import com.niiwoo.civet.user.service.myCustomer.MyCustomerInfoDubboService;
import com.niiwoo.tripod.base.component.PrivacyMasks;
import com.niiwoo.tripod.provider.dto.response.PageResponseDTO;
import com.niiwoo.tripod.provider.exception.BizException;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.FastDateFormat;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;

import java.util.*;
import java.util.concurrent.CompletableFuture;

/**
 * Created by laichunjing on 2018/04/25.
 */
@Service(version = "1.0.0")
public class MyCustomerInfoDubboServiceImpl implements MyCustomerInfoDubboService {

    @Autowired
    MyCustomerInfoService myCustomerInfoService;
    //意见反馈输入长度限制
    private static final double FEED_BACK_SAVE_MAXIMUM_LENGTH = 200;
    //问题PV、UV统计
    private static final String QUESTION = "question_";
    //关键词PV、UV统计
    private static final String KEYWORD = "keyword_";

    /**
     * 客服首页数据
     * @param userId
     * @return
     */
    @Override
    public MyCustomerHomePageResponseDTO myCustomerHomePageList(String userId) {
        return  myCustomerInfoService.myCustomerHomePageList(userId);
    }

    /**
     * 问题搜索
     * @param content
     * @return
     */
    @Override
    public QueryContentResponseDTO queryProblemsList(String content) {
        return  myCustomerInfoService.queryProblemsListByContent(content);
    }

    /**
     * 关键词列表
     * @param userId
     * @return
     */
    @Override
    public KeyWordListResponseDTO queryKeyWordList(String userId) {
        return myCustomerInfoService.queryKeyWordList(userId);
    }

    /**
     * 根据关键词查询问题列表
     * @param keyWordId
     * @param userId
     * @return
     */
    @Override
    public ProblemListResponseDTO queryProblemListByKeyword(Long keyWordId, String  userId) {
        return myCustomerInfoService.queryProblemListByKeyword(keyWordId,userId);
    }
    /**
     * 查看问题详情
     */
    @Override
    public ProblemDetailResponseDTO showQuestionDetail(Long questionId,Long keywordId,String userId){
        return myCustomerInfoService.showQuestionDetail(questionId,keywordId,userId);
    }

    /**
     * 修改问题状态
     * @param requestDTO
     * @return
     */
    @Override
    public ProblemStatusResponseDTO updateAnswerStatus(ProblemStatusRequestDTO requestDTO){
        int num = myCustomerInfoService.updateAnswerStatus(requestDTO);
        if(num>0){
            myCustomerInfoService.accountButtonPVAndUV(requestDTO);
        }
        ProblemStatusResponseDTO dto=myCustomerInfoService.queryNewQuestionStatus(num,requestDTO);
        return dto;
    }
    /**
     * 保存反馈结果
     */
    @Override
    public boolean saveFeedBackInfo(NewFeedBackSaveRequestDTO requestDTO){
        if(myCustomerInfoService.getLength(requestDTO.getContent()) > FEED_BACK_SAVE_MAXIMUM_LENGTH){
            throw new BizException("USR10018");
        }
        return myCustomerInfoService.saveFeedBackInfo(requestDTO);
    }
    /**
     * 查询反馈记录
     * @param requestDTO
     * @return
     */
    @Override
    public PageResponseDTO<FeedBackInfoResponseDTO> showFeedBackRecord(NiiwooScorePageRequestDTO requestDTO){
        return myCustomerInfoService.showFeedBackRecord(requestDTO);
    }

    /**
     * 反馈详情
     * @param requestDTO
     * @return
     */
    @Override
    public FeedBackDetailResponseDTO feedBackDetails(FeedBackDetailRequestDTO requestDTO){
        return myCustomerInfoService.feedBackDetails(requestDTO);
    }

    /**
     * 追加反馈
     * @param requestDTO
     */
    @Override
    public boolean appendFeedBackInfo(AppendFeedBackRequestDTO requestDTO){
        if(myCustomerInfoService.getLength(requestDTO.getFeedBackContent()) > FEED_BACK_SAVE_MAXIMUM_LENGTH){
            throw new BizException("USR10018");
        }
        return myCustomerInfoService.appendFeedBackInfo(requestDTO);
    }

    /**
     * 反馈解决状态
     * @param requestDTO
     * @return
     */
    @Override
    public boolean feedBackSolveStatus(FeedBackStatusRequestDTO requestDTO){
        return myCustomerInfoService.feedBackSolveStatus(requestDTO);
    }
    /**
     * 统计PV和UV
     * @param requestDTO
     * @return
     */
    @Override
    public boolean accountPVAndUV(AccountPVAndUVRequestDTO requestDTO){
        //问题PV、UV统计
        if(null!=requestDTO.getQuestionId()){
            return myCustomerInfoService.accountPVAndUV(requestDTO,requestDTO.getQuestionId().toString()+QUESTION);
        }
        //关键词PV、UV统计
        if(null!=requestDTO.getKeywordId()){
            return myCustomerInfoService.accountPVAndUV(requestDTO,requestDTO.getKeywordId().toString()+KEYWORD);
        }
        return false;
    }
    /**
     * 反馈是否最新回复
     * @param userId
     * @return
     */
    @Override
    public FeedBackIsNewReceiveResponseDTO feedBackisNewReceive(String userId){
        return myCustomerInfoService.feedBackisNewReceive(userId);
    }


    /*@Override
    public boolean feedBackSave(FeedBackSaveRequestDTO requestDTO) {
        if(userBasicInfoService.getLength(requestDTO.getContent()) > FEED_BACK_SAVE_MAXIMUM_LENGTH){
            throw new BizException("USR10018");
        }
        return userBasicInfoService.feedBackSave(requestDTO);*/
}




